#include<iostream>
#include <vector>
using namespace std;

class Solution {
public:
    int peakIndexInMountainArray(vector<int>& arr) {
        int l = 1, r = arr.size() - 2;
        while (l < r) {
            int mid = l + (r - l) / 2;
            if (arr[mid] > arr[mid - 1] && arr[mid] > arr[mid + 1]) {
                return mid;
            }
            else {
                if (arr[mid] > arr[mid + 1]) {
                    r = mid;
                }
                else {
                    l = mid + 1;
                }
            }
        }
        return  l;
    }
};

int main()
{
    vector<int> nums = { 55,59,63,99,97,94,84,81,79,66,40,38,33,23,22,21,17,9,7 };
    cout << Solution().peakIndexInMountainArray(nums);
    return 0;
}